package com.huawei.appmarket.service.settings.card;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build.VERSION;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardkit.bean.CardBean;
import huawei.widget.HwSwitch;
import o.AccountBussinessListener;
import o.ccp;
import o.PermissionChecker;
import o.cfw;
import o.cgz;
import o.cvt;
import o.der.f;
import o.Logger;
import o.dtv;
import o.eod;
import o.eoj;
import o.euf;
import o.NetWorkUtil;

public class SettingAppSyncCard extends BaseSettingCard {
    public static final String ˎ = (SettingAppSyncCard.class.getSimpleName() + "_permission_request_status");
    private HwSwitch ˊ;
    private Context ˋ;
    private AccountBussinessListener ˏ = new AccountBussinessListener(this) {
        final /* synthetic */ SettingAppSyncCard ˎ;

        {
            this.ˎ = r1;
        }

        public void onAccountBusinessResult(ccp o_ccp) {
            if (102 != o_ccp.ˎ) {
                Logger.ˎ("SettingAppSyncCard", "LOGIN fail");
                this.ˎ.ˋ(false);
            } else if (PermissionChecker.ˋ((Activity) this.ˎ.ˋ, 14)) {
                Logger.ˎ("SettingAppSyncCard", "LOGIN success checkPersmission");
                return;
            } else {
                this.ˎ.ˋ(true);
            }
            eoj.ˋ().ˊ("AppSynLogin");
        }
    };
    private boolean ॱ = false;

    class d implements OnCheckedChangeListener {
        final /* synthetic */ SettingAppSyncCard ˏ;

        private d(SettingAppSyncCard settingAppSyncCard) {
            this.ˏ = settingAppSyncCard;
        }

        public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
            this.ˏ.ॱ = compoundButton.isChecked();
            Logger.ˎ("SettingAppSyncCard", "onCheckedChanged appSynFlag=" + this.ˏ.ॱ);
            euf.ˎ().ˊ(this.ˏ.ॱ);
            if (!this.ˏ.ॱ) {
                return;
            }
            if (UserSession.getInstance().isLoginSuccessful()) {
                this.ˏ.ˊ();
                return;
            }
            Logger.ˎ("SettingAppSyncCard", "UserSession.getInstance().isLoginSuccessful()=" + UserSession.getInstance().isLoginSuccessful());
            eoj.ˋ().ˎ("AppSynLogin", this.ˏ.ˏ);
            eod.ॱ(this.ˏ.ˋ);
        }
    }

    public SettingAppSyncCard(Context context) {
        super(context);
        this.ˋ = context;
    }

    public static void ˋ(Activity activity) {
        if (VERSION.SDK_INT >= 23 && activity != null) {
            Intent intent = activity.getIntent();
            if (intent != null) {
                int i;
                int intExtra = intent.getIntExtra(ˎ, 0);
                if (activity.checkSelfPermission("android.permission.READ_PHONE_STATE") == 0) {
                    i = 1;
                } else {
                    i = 0;
                }
                if (intExtra == 1) {
                    if (i != 0) {
                        intent.putExtra(ˎ, 3);
                    }
                } else if (intExtra != 2) {
                } else {
                    if (i != 0) {
                        intent.putExtra(ˎ, 3);
                    } else {
                        intent.putExtra(ˎ, 0);
                    }
                }
            }
        }
    }

    public cgz ˏ(View view) {
        super.ˏ(view);
        TextView textView = (TextView) view.findViewById(o.der.d.ʽʻ);
        ((TextView) view.findViewById(o.der.d.ʽʼ)).setText(f.ˋʾ);
        textView.setText(NetWorkUtil.getWifiResId(this.ˋ, f.ˊﾞ));
        this.ˊ = (HwSwitch) view.findViewById(o.der.d.ˇ);
        this.ˊ.setOnCheckedChangeListener(new d());
        ʽ(view);
        return this;
    }

    public void ˏ(CardBean cardBean) {
        super.ˏ(cardBean);
        ˋ();
    }

    private void ˋ() {
        if (this.ˊ != null) {
            if (VERSION.SDK_INT < 23) {
                Logger.ˎ("SettingAppSyncCard", "onActivityResume < M");
                this.ॱ = euf.ˎ().ˋ();
            } else if (-1 == this.ˋ.checkSelfPermission("android.permission.READ_PHONE_STATE")) {
                Logger.ˎ("SettingAppSyncCard", "onActivityResume PERMISSION_DENIED appSynFlag=false");
                this.ॱ = false;
            } else {
                boolean z;
                boolean z2 = ((Activity) this.ˋ).getIntent().getIntExtra(ˎ, 0) == 3;
                if (z2) {
                    ((Activity) this.ˋ).getIntent().putExtra(ˎ, 0);
                }
                if (euf.ˎ().ˋ() || z2) {
                    z = true;
                } else {
                    z = false;
                }
                this.ॱ = z;
                Logger.ˎ("SettingAppSyncCard", "onActivityResume get from sf , appSynFlag=" + this.ॱ);
            }
            if (this.ˊ.isChecked() != this.ॱ) {
                Logger.ˎ("SettingAppSyncCard", "onActivityResume setChecked appSynFlag=" + this.ॱ);
                this.ˊ.setChecked(this.ॱ);
            }
            euf.ˎ().ˊ(this.ॱ);
        }
    }

    private void ˊ() {
        if (PermissionChecker.ˋ((Activity) this.ˋ, 14)) {
            Logger.ˎ("SettingAppSyncCard", "onCheckedChanged checkPersmission");
            ((Activity) this.ˋ).getIntent().putExtra(ˎ, 1);
            return;
        }
        Logger.ˎ("SettingAppSyncCard", "refreshSynTime()");
        cvt o_dtv = new dtv();
        o_dtv.ˊ(1);
        cfw.ˎ(o_dtv, null);
    }

    private void ˋ(final boolean z) {
        if (this.ˊ != null) {
            Logger.ˎ("SettingAppSyncCard", "LOGIN setChecked flag=" + z);
            new Handler(Looper.getMainLooper()).post(new Runnable(this) {
                final /* synthetic */ SettingAppSyncCard ॱ;

                public void run() {
                    this.ॱ.ˊ.setChecked(z);
                    if (z) {
                        this.ॱ.ˊ();
                    }
                    euf.ˎ().ˊ(z);
                }
            });
        }
    }
}
